package it.bit.jlightqueryer.conn;

import java.sql.Connection;
import java.sql.Driver;
import java.sql.DriverPropertyInfo;
import java.sql.SQLException;
import java.util.Properties;

/**
 * Class to hack JVM ClassLoader.
 * Taked from http://quack.kfu.com/~nsayer/Java/dyn-jdbc.html
 * @author PerezDeQueya80
 */
public class DriverShim implements Driver {
	private Driver driver;

	DriverShim(Driver d) {
		this.driver = d;
	}

	public boolean acceptsURL(String url) throws SQLException {
		return driver.acceptsURL(url);
	}

	public Connection connect(String url, Properties info) throws SQLException {
		return driver.connect(url, info);
	}

	public Connection connect(String url, String user, String password) throws SQLException {
		Properties info = new Properties();
		if (user != null) {
		    info.put("user", user);
		}
		if (password != null) {
		    info.put("password", password);
		}
		return connect(url, info);
	}

	public int getMajorVersion() {
		return driver.getMajorVersion();
	}

	public int getMinorVersion() {
		return driver.getMinorVersion();
	}

	public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) throws SQLException {
		return driver.getPropertyInfo(url, info);
	}

	public boolean jdbcCompliant() {
		return driver.jdbcCompliant();
	}

	public String toString() {
		return driver.toString();
	}
}
